package org.ranch.dao.impl;

import org.hibernate.Query;
import org.ranch.dao.ConceptDAO;
import org.ranch.model.Concept;
import org.springframework.stereotype.Repository;

/**
 * Implements the {@link ConceptDAO} interface to provide CRUD operations for
 * the {@link Concept} entities using hibernate as the ORM strategy
 * 
 * 
 */
@Repository("conceptDAO")
public class HibernateConceptDAOImpl extends BaseDAOImpl<Concept> implements ConceptDAO {

    /*
     * (non-Javadoc)
     * 
     * @see org.mak.cis.mohr.dao.ConceptDAO#exists(java.lang.String)
     */
    @Override
    public boolean exists(String name) {
	Query query = super.getSession()
		.createQuery("select id from Concept c where c.name = :name")
		.setString("name", name);
	Object result = query.uniqueResult();
	if(result != null)
	    return true;
	
	return false;
    }

    /*
     * (non-Javadoc)
     * 
     * @see org.mak.cis.mohr.dao.ConceptDAO#getConceptIdByName(java.lang.String)
     */
    @Override
    public String getConceptIdByName(String name) {
	Query query = super.getSession()
		.createQuery("select id from Concept c where c.name = :name")
		.setString("name", name);
	return (String) query.uniqueResult();
    }

}
